//
//  UIImage+Extension.swift
//  sina
//
//  Created by 张鹏 on 16/5/29.
//  Copyright © 2016年 ZP. All rights reserved.
//

import UIKit


extension UIImage {

   class func snapShotCurrentWindow() -> UIImage {
    
        let window = UIApplication.sharedApplication().keyWindow
    //开启图形上下文
        
        //0 : 获取当前屏幕大小的图片
        UIGraphicsBeginImageContextWithOptions((window?.bounds.size)!, false, 0)
        
    //需要将window中显示的内容滑动到上下文中
        window?.drawViewHierarchyInRect((window?.bounds)!, afterScreenUpdates: false)
        
        
    //从图形上下文中获取图片
    
    let image = UIGraphicsGetImageFromCurrentImageContext()
    
    //关闭图形上下文
        UIGraphicsEndPDFContext()


    
    return image
    }

}
